<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    width="800px"
    @close="close"
  >
    <el-descriptions
      ref="form"
      class="margin-top"
      title="审核详情"
      :column="2"
      border
      :model="form"
    >
      <el-descriptions-item v-if="form.type == 1">
        <template slot="label">
          <i class="el-icon-pie-chart"></i>
          基本信息
        </template>
        <el-tag size="small">
          {{
            form.projectName +
            '-' +
            transferData(form.partNames) +
            '-' +
            form.partName
          }}
        </el-tag>
      </el-descriptions-item>
      <el-descriptions-item v-if="form.type == 2">
        <template slot="label">
          <i class="el-icon-pie-chart"></i>
          基本信息
        </template>
        <el-tag size="small">
          {{
            form.projectName +
            '-' +
            transferData(form.partNames) +
            '-' +
            form.partName
          }}
        </el-tag>
      </el-descriptions-item>
      <el-descriptions-item v-if="form.estateLocation == 1">
        <template slot="label">
          <i class="el-icon-location-outline"></i>
          目标位置
        </template>
        <el-tag size="small">{{ form.partName }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item v-if="form.type == 2">
        <template slot="label">
          <i class="el-icon-location-outline"></i>
          目标位置
        </template>
        <el-tag size="small">{{ form.estateLocation }}</el-tag>
      </el-descriptions-item>
      <!-- <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-c-scale-to-original"></i>
          类别
        </template>
        <el-tag size="small">
          {{ form.type == 1 ? '项目大事记' : '房屋节点' }}
        </el-tag>
      </el-descriptions-item> -->
      <!-- <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-office-building"></i>
          处理人
        </template>
        <el-tag size="small">{{ form.handlerUserId }}</el-tag>
      </el-descriptions-item> -->
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-time"></i>
          开工时间
        </template>
        <el-tag size="small" type="info">{{ form.startTime }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-time"></i>
          结工时间
        </template>
        <el-tag size="small">{{ form.endTime }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-location-outline"></i>
          审核状态
        </template>
        <el-tag
          size="small"
          :type="
            form.eventStatus == 3
              ? 'success'
              : form.eventStatus == 4
              ? 'danger'
              : form.eventStatus == 1
              ? 'info'
              : 'warning'
          "
        >
          {{ getValue(form.eventStatus) }}
        </el-tag>
      </el-descriptions-item>
    </el-descriptions>
    <el-descriptions class="margin-top" :column="1" border :model="form">
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-chat-line-square"></i>
          反馈描述
        </template>
        <el-tag size="small">{{ form.feedBack }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-picture-outline"></i>
          现场情况
        </template>
        <div v-if="form.imgs != null">
          <el-row :gutter="50">
            <div v-for="(img, i) in form.imgs.split(',')" :key="i">
              <el-col :span="8">
                <el-image
                  style="width: 100px; height: 100px"
                  :src="transfer(img)"
                  :preview-src-list="[transfer(img)]"
                ></el-image>
              </el-col>
            </div>
          </el-row>
        </div>
      </el-descriptions-item>
    </el-descriptions>
    <div slot="footer" class="dialog-footer">
      <el-button
        v-if="form.eventStatus == 2"
        type="danger"
        size="small"
        @click="confirm(false)"
      >
        不通过审核
      </el-button>
      <el-button
        v-if="form.eventStatus == 2"
        type="primary"
        size="small"
        @click="confirm(true)"
      >
        通过审核
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { modSingleItem } from '@/api/houseNode'
  import _net from '../../../config/net.config'

  import _ from 'lodash'
  export default {
    name: 'CheckNote',
    data() {
      return {
        setStatus: {},
        form: {},
        title: '',
        dialogFormVisible: false,
      }
    },
    computed: {
      transfer(id) {
        return function (id) {
          console.log(_net.baseURL)
          // let base = 'https://app.aixinfang.vip'
          let base = _net.baseURL
          return base + '/file/download?fileId=' + id
        }
      },
    },
    methods: {
      transferData(value) {
        if (typeof value != undefined) {
          let xx = value.slice(1, value.length)
          let _string = xx.toString()
          let _result = _string.replaceAll(',', '-')
          return _result
        }
      },
      getValue(value) {
        switch (value) {
          case 1:
            return '待上传'
          case 2:
            return '未审核'
          case 3:
            return '已通过'
          case 4:
            return '未通过'
        }
      },
      showEdit(row) {
        if (row.type == 1) {
          this.title = '项目大事记审核'
        } else {
          this.title = '房屋节点审核'
        }
        this.setStatus = row
        this.form = _.cloneDeep(row)
        this.dialogFormVisible = true
      },
      close() {
        this.dialogFormVisible = false
        // this.$emit('fetch-data')
      },
      async confirm(value) {
        let _form = {}
        _form.eventStatus = value ? 3 : 4
        _form.eventId = this.form.eventId
        const { data } = await modSingleItem(_form)
        if (data.status === 0) {
          this.dialogFormVisible = false
          // this.setStatus.eventStatus = 2
          this.$emit('fetch-data')
        } else {
          // this.setStatus.eventStatus = 3
          // if (value) {
          //   this.$emit('fetch-data')
          //   this.dialogFormVisible = false
          // } else {
          this.$baseMessage(data.message, 'error')
          // }
        }
      },
    },
  }
</script>
